using System;
using System.Xml;
using System.Collections;

namespace ScenarioFramework.Modules.FormHelper
{
	//*********************************************************************
	//
	// Action Class
	//
	// The XMLAction class represents a single operation to do witch contains
	// configurtion tags width configurated parameters to delivery to the 
	// FormHelper that execute commands on process or activity and returns
	// ok result or an Url to redirect web application that calls it
	//
	//*********************************************************************

	public class XMLAction : bOSdotNET.XML.Data.XMLObject
	{
		public const string MAIN_NODE	= "Action";

		private const string NAME_ATTRIBUTE			= "Name";
		private const string DESCRIPTION_NODE		= "Description";
		private const string REDIRECTURL_NODE		= "RedirectUrl";
		
		/** FIELDS **/

		public string sName;
		public string sDescription;
		public string sRedirectUrl;

		public XMLProcessAction ProcessAction;

		public XMLFormAttributes formAttributes;
		public XMLResources Resouces;


		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Width simple Property **/
		public XMLAction()
		{
			this.Init();
		}

		
		/** CONSTRUCTOR Width XML parsering**/
		public XMLAction(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		override public void Init()
		{
			sName= string.Empty;
			sDescription= string.Empty;
			sRedirectUrl= string.Empty;

			ProcessAction = new XMLProcessAction();
			formAttributes = new XMLFormAttributes();
			this.Resouces= new XMLResources();

		}

		/** PROPERTIES **/


		public string Name 
		{
			get { return sName; }
			set { sName = value; }
		}

		public string Description 
		{
			get { return sDescription; }
			set { sDescription = value; }
		}

		public string RedirectUrl 
		{
			get { return sRedirectUrl; }
			set { sRedirectUrl = value; }
		}
		
		/** INSTANCE METHODS **/

		/** Parsering method for filling the entity **/
		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			/** find the attributes situated on the root tag **/
			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLAction.NAME_ATTRIBUTE:
						sName = node.InnerText;
						break;
				}
			}

			/** find the sub tags witch contains action values **/
			for ( int i=0; i<node2Parse.ChildNodes.Count; i++)
			{
				node = node2Parse.ChildNodes[i];

				switch (node.Name) 
				{
					case XMLAction.DESCRIPTION_NODE:
						sDescription = node.InnerText;
						break;

					case XMLAction.REDIRECTURL_NODE:
						sRedirectUrl = node.InnerText;
						break;

					/** define the subcollection of the action By parsering the subtags **/
					case XMLProcessAction.MAIN_NODE:
						ProcessAction.Parse(node);
						break;

					case XMLFormAttributes.MAIN_NODE:
						formAttributes.Parse(node);
						break;

					case XMLResources.MAIN_NODE:
						Resouces.Parse(node);
						break;

				} 
			}
		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(XMLAction.MAIN_NODE);
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLAction.NAME_ATTRIBUTE, sName) );
			xmlNode.AddNode ( new bOSdotNET.XML.XMLNode (XMLAction.DESCRIPTION_NODE, sDescription) );
			xmlNode.AddNode ( new bOSdotNET.XML.XMLNode (XMLAction.REDIRECTURL_NODE, sRedirectUrl) );
			xmlNode.AddNode ( ProcessAction.GetXMLNode() );
			
			return xmlNode;
		}
	
	}
}
